/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package downloader.IHM;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
import downloader.*;
import java.awt.FlowLayout;
import java.awt.GridLayout;

/**
 *
 * @author Julien
 */
public class MainWindows extends JFrame implements WindowListener, ActionListener {

    private AddURLDialogBox myAddURLDialogBox;
    private String myTargetFolder = "C:\\Download";
    private SettingsDialog mySettingsDialog;
    private MainMenuBar myMainMenuBar;
    private JPanel progressPanel;

    @SuppressWarnings("LeakingThisInConstructor")
    public MainWindows(){
        this.setLayout(new BorderLayout());
        this.setTitle("Julien Downloader");
        this.setVisible(true);
        this.addWindowListener(this);
        this.setSize(500,500);
        myMainMenuBar = new MainMenuBar(this);
        this.add(myMainMenuBar, BorderLayout.NORTH);
        myAddURLDialogBox = new AddURLDialogBox(this);
        mySettingsDialog = new SettingsDialog(this);
        this.setLocation(200, 200);
        progressPanel = new JPanel();
        progressPanel.setLayout(new FlowLayout());
        this.add(progressPanel, BorderLayout.CENTER);
        //this.pack();
        this.validate();
        this.repaint();
    }

    public void newDownload(String newUrl){
        FileToDownload myFileToDownload = new FileToDownload(newUrl,myTargetFolder, this);
        myFileToDownload.start();
    }

    public void setMyTargetFolder(String myTargetFolder){
        this.myTargetFolder=myTargetFolder;
    }

    public String getMyTargetFolder(){
        return myTargetFolder;
    }

    public void addProgressBar(JProgressBar myProgressBar){
        // progressPanel.add(myProgressBar);
//        JPanel temp = new JPanel();
//        temp.setLayout(new FlowLayout());
//        temp.setSize(myProgressBar.getSize());
//        temp.add(myProgressBar);
        myProgressBar.setSize(800, 25);
        progressPanel.add(myProgressBar);
        this.validate();
        this.repaint();
        //this.pack();
    }

    public void windowOpened(WindowEvent e) {
    }

    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }

    public void windowClosed(WindowEvent e) {   
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }

    public void actionPerformed(ActionEvent e) {
        JButton temp = (JButton) e.getSource();
        if (temp.getText().equalsIgnoreCase("Add URL")){
            myAddURLDialogBox.getNewUrl();
        }
        if (temp.getText().equalsIgnoreCase("Settings")){
            mySettingsDialog.showSettingsDialog();
        }
        if (temp.getText().equalsIgnoreCase("Exit")){
            System.exit(0);
        }
    }

}
